﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;

using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.Text;
using System.Collections.Generic;

/// <summary>
/// Summary description for BaseEntity
/// </summary>
public class BaseEntity : IDbTable
{
    List<string> Errors = new List<string>();

    public List<string> Error
    {
        get
        {
            return Errors;
        }

    }

    public void AddError(string message)
    {
        Errors.Add(message);
    }

    public bool IsValid
    {
        get
        {
            return Errors.Count == 0;
        }
    }

    public string BuildSEO(string convertedString)
    {

        string subject = convertedString.Trim();

        if (subject.Length > 180)
            subject = subject.Substring(0, 180);

        Regex regex = new Regex(@"\p{IsCombiningDiacriticalMarks}+");
        string strFormD = subject.Normalize(System.Text.NormalizationForm.FormD);
        subject = regex.Replace(strFormD, String.Empty).Replace('\u0111', 'd').Replace('\u0110', 'D');

        subject = Regex.Replace(subject, @"\s+", "-");
        subject = Regex.Replace(subject, @"[^A-Za-z0-9_-]", "");
        //subject = Regex.Replace(subject, @"-", " ");
        return subject;
    }

    public string BuildSEO(object stringObject)
    {
        if (stringObject == null) return "";
        return BuildSEO(stringObject.ToString());
    }

}

